package com.bjtu.lms.action.book;

import com.bjtu.lms.model.Book;
import com.bjtu.lms.service.BookService;
import com.opensymphony.xwork2.ActionSupport;

/**
 *
 * @author yilee
 */
public class DeleteBookAction extends ActionSupport {

	private int id;
	private BookService bookService;
	private String result;

	public String getResult() {
		return result;
	}

	public void setResult(String result) {
		this.result = result;
	}

	public BookService getBookService() {
		return bookService;
	}

	public void setBookService(BookService bookService) {
		this.bookService = bookService;
	}

	public int getId() {
		return id;
	}

	public void setId(int id) {
		this.id = id;
	}

	@Override
	public String execute() throws Exception {
		Book b = bookService.findBooksById(id);
		if (b == null) {
			result = "{suc:0, msg:'图书不存在.'}";
		} else {
			bookService.deleteBookById(id);
			result = "{suc:1, msg:'删除成功.'}";
		}
		return SUCCESS;
	}
}
